package com.gitee.wsl.compose.ui.richtext.content.span

import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import com.gitee.wsl.compose.ui.richtext.content.ParagraphContentDrawer
import com.gitee.wsl.compose.ui.richtext.content.ParagraphLayoutInfo

/**
 * Implementation of [ParagraphContentDrawer] to
 * render the background color of the lines to which the span is attached.
 *
 * @see ParagraphContentDrawer
 * @see LineBackgroundSpan
 */
private class LineBackgroundContentDrawer(
    val color: Color,
) : ParagraphContentDrawer {

    override fun onDraw(
        drawScope: DrawScope,
        layoutInfo: ParagraphLayoutInfo
    ) {
        drawScope.drawRect(
            color = color,
            topLeft = Offset(0f, layoutInfo.top),
            size = Size(
                width = layoutInfo.result.size.width.toFloat(),
                height = layoutInfo.height
            )
        )
    }
}